package org.zoomdev.zoom.common.caster;


import com.alibaba.fastjson2.JSON;

class Bean2Bean implements ValueCaster {
    private final Class toType;
    private final Class fromType;

    public Bean2Bean(Class fromType, Class toType) {
        this.toType = toType;
        this.fromType = fromType;
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    public Object to(Object src) {
        byte[] bytes = JSON.toJSONBytes(src);
        return JSON.parseObject(bytes, toType);
    }

}
